<%if (t.isProtocol == 1) {%>
${g.copyright!}
<%}%>
package ${g.codePackage}.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.csinc.generate.core.base.annotion.BussinessLog;
import com.csinc.generate.core.base.annotion.Permission;
import com.csinc.generate.core.base.controller.BaseController;
import com.csinc.generate.core.common.factory.PageFactory;
import com.csinc.generate.core.exception.CsincException;
import com.csinc.generate.core.exception.CsincExceptionEnum;
import com.csinc.generate.core.utils.lang.StringUtils;
import ${g.codePackage}.model.${g.entityName}Model;
import ${g.codePackage}.service.I${g.entityName}Service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

<%if (t.api == 1) {%>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
<%}%>
/**
 * ${g.name}控制器
 *
 * @author ${g.author}
 * @Date ${g.date}
 */
<%if (t.api == 1) {%>
@Api("${g.name}")
<%}%>
@Slf4j
@Controller
@RequestMapping("/${strutil.toLowerCase(g.entityName)}")
public class ${g.entityName}Controller extends BaseController {

    private String PREFIX = "/biz/${strutil.toLowerCase(g.entityName)}/";

    @Autowired
    private I${g.entityName}Service ${g.lowerEntityName}Service;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "${strutil.toLowerCase(g.entityName)}.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/goto_add")
    public String gotoAdd() {
        return PREFIX + "${strutil.toLowerCase(g.entityName)}_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/goto_update/{id}")
    public String gotoUpdate(@PathVariable Integer id, Model model) {
        model.addAttribute("${strutil.toLowerCase(g.entityName)}", ${g.lowerEntityName}Service.selectById(id));
        return PREFIX + "${strutil.toLowerCase(g.entityName)}_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(${g.entityName}Model model,HttpServletRequest req, HttpServletResponse res) {
        Page<${g.entityName}Model> page = new PageFactory<${g.entityName}Model>().defaultPage();
//        page.setRecords(${g.lowerEntityName}Service.selectPage(page,model,new EntityWrapper<${g.entityName}Model>()));
        return super.packForBT(${g.lowerEntityName}Service.selectPage(page,new EntityWrapper<${g.entityName}Model>()));
    }

    <%if (t.isLog == 1) {%>
    @BussinessLog(value = "${g.name}新增", key = "?" )
    <%}%>
    @RequestMapping(value = "/add")
    @Permission
    @ResponseBody
    public Object add(${g.entityName}Model model) {
        ${g.lowerEntityName}Service.insert(model);
        return SUCCESS_TIP;
    }

    <%if (t.isLog == 1) {%>
    @BussinessLog(value = "${g.name}删除", key = "id" )
    <%}%>
    @RequestMapping(value = "/delete")
    @Permission
    @ResponseBody
    public Object delete(Integer id) {
        ${g.lowerEntityName}Service.deleteById(id);
        return SUCCESS_TIP;
    }

    <%if (t.isLog == 1) {%>
    @BussinessLog(value = "${g.name}修改", key = "id" )
    <%}%>
    @RequestMapping(value = "/update")
    @Permission
    @ResponseBody
    public Object update(${g.entityName}Model model) {
        if (StringUtils.isOneEmpty(model.getId())) {
        throw new CsincException(CsincExceptionEnum.REQUEST_NULL);
        }
        ${g.lowerEntityName}Service.updateById(model);
        return SUCCESS_TIP;
    }

    @RequestMapping(value = "/detail")
    @ResponseBody
    public ${g.entityName}Model detail(EntityWrapper<${g.entityName}Model> model) {
        return ${g.lowerEntityName}Service.selectOne(model);
    }
}